package net.sk.china.city.talk.service.impl.system;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import net.sk.china.city.talk.dao.system.SystemRoleMenuDao;
import net.sk.china.city.talk.model.system.CityRoleMenu;
import net.sk.china.city.talk.service.system.SystemRoleMenuService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.stream.Collectors;

/**
 * SystemRoleMenuServiceImpl 接口实现
 * +----------------------------------------------------------------------
 * // | Talk To [ 聊来改善地区金融服务环境，助力企业发展 ]
 * // +----------------------------------------------------------------------
 * // | Copyright (c) 2018-2024 聊来 All rights reserved.
 * // +----------------------------------------------------------------------
 * // | Licensed ( <a href="http://www.apache.org/licenses/LICENSE-2.0">apache</a> )
 * // +----------------------------------------------------------------------
 * // | @Author: 聊来 <18970881148@qq.com>
 * // +----------------------------------------------------------------------
 * // | DateTime: 2024/6/3 15:52
 * // +----------------------------------------------------------------------
 */

@Service
public class SystemRoleMenuServiceImpl extends ServiceImpl<SystemRoleMenuDao, CityRoleMenu> implements SystemRoleMenuService {

    @Resource
    private SystemRoleMenuDao dao;

    /**
     * 通过角色id删除
     * @param rid 角色id
     * @return {@code boolean}
     */
    @Override
    public boolean deleteByRid(Integer rid) {
        LambdaUpdateWrapper<CityRoleMenu> query = Wrappers.lambdaUpdate();
        query.eq(CityRoleMenu::getRid, rid);
        return dao.delete(query) > 0;
    }

    /**
     * 通过角色id获取菜单列表
     * @param rid 角色id
     * @return {@code List<Integer>}
     */
    @Override
    public List<Integer> getMenuListByRid(Integer rid) {
        LambdaQueryWrapper<CityRoleMenu> query = Wrappers.lambdaQuery();
        query.select(CityRoleMenu::getMenuId);
        query.eq(CityRoleMenu::getRid, rid);
        List<CityRoleMenu> roleMenuList = dao.selectList(query);
        return roleMenuList.stream().map(CityRoleMenu::getMenuId).collect(Collectors.toList());
    }
}
